/*
 * seqbusterAboutBox.java
 */

package seqbuster;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.awt.Color;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
//import javax.swing.JFileChooser;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
//import org.jdesktop.application.Action;

import seqbuster.AdaptorRecognition.*;

public class CusAnnFrame extends javax.swing.JDialog {
    int numexp=0;
    public CusAnnFrame(java.awt.Frame parent) throws SQLException {
        super(parent);
        initComponents();
        getRootPane().setDefaultButton(CloseCusBut);
        showinfo();
    }

    public void showinfo() throws SQLException{

        String host=SeqBusterView.HosMysText.getText();
        String user=SeqBusterView.UseMysText.getText();
        String pssw=SeqBusterView.PswMysText.getText();
        String namepro=SeqBusterView.loaprotext.getText();
        String port=SeqBusterView.PorMysText.getText();
        if (!port.matches("")){host=host+":"+port;}
        Connection con = (Connection) DriverManager.getConnection ("jdbc:mysql://"+host+"/"+namepro,user,pssw);
        Statement statment = (Statement) con.createStatement();
        String readsamples="select `name` from `experiments` where `description` not like 'noshow'";
        ResultSet rs=statment.executeQuery(readsamples);
        while (rs.next()) {
            ExpList.addItem(rs.getString(1));
            numexp++;

        }

        rs=statment.executeQuery("select `specie` from `seqbuster`.`genome`");

        while (rs.next()) {
            SpeList.addItem(rs.getString(1));

        }

        rs=statment.executeQuery("select count(*) from `seqbuster`.`genome`");
        rs.next();
        NumGenText.setText(rs.getString(1));
        if (rs.getInt(1)==0){
            dobut.setEnabled(false);
        }
        rs=statment.executeQuery("select count(*) from `seqbuster`.`track`");
        rs.next();
        NumTraText.setText(rs.getString(1));
        //int numtrack=Integer.parseInt(rs.getString(1));
        readsamples="select * from `seqbuster`.`track`";
//        Vector listtrack=new Vector();
        rs=statment.executeQuery(readsamples);
        DefaultListModel model = new DefaultListModel();
        //int p=tralist.getModel().getSize();
        int p=0;
        tralist.removeAll();
        while (rs.next()) {

            model.add(p,rs.getString(1));
            p++;

        }

        tralist.setModel(model);
        tralist.repaint();


        rs.close();
        statment.close();
        con.close();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        miann = new javax.swing.JPanel();
        jButton4 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        DBList = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        NumGenText1 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        MisMirAnnText = new javax.swing.JTextField();
        jButton7 = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        AddMirAnnText = new javax.swing.JTextField();
        TriMirAnnText = new javax.swing.JTextField();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        cusann = new javax.swing.JPanel();
        LoaGenBut = new javax.swing.JButton();
        freqtext = new javax.swing.JTextField();
        SpeList = new javax.swing.JComboBox();
        GenList = new javax.swing.JComboBox();
        addtext = new javax.swing.JTextField();
        mistext = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tralist = new javax.swing.JList();
        LoaTraBut = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        lablefreq = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel8 = new javax.swing.JLabel();
        NumGenText = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        NumTraText = new javax.swing.JTextField();
        jButton6 = new javax.swing.JButton();
        nameana = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        ExpList = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        dobut = new javax.swing.JButton();
        CloseCusBut = new javax.swing.JButton();
        probar = new javax.swing.JProgressBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setModal(true);
        setName("aboutBox"); // NOI18N
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        miann.setName("miann"); // NOI18N
        miann.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(seqbuster.SeqBusterApp.class).getContext().getResourceMap(CusAnnFrame.class);
        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setName("jButton4"); // NOI18N
        miann.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 50, 200, -1));

        jSeparator1.setName("jSeparator1"); // NOI18N
        miann.add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 110, 520, 20));

        DBList.setName("DBList"); // NOI18N
        miann.add(DBList, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 130, 140, 30));

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N
        miann.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 140, -1, -1));

        NumGenText1.setBackground(resourceMap.getColor("NumGenText1.background")); // NOI18N
        NumGenText1.setEditable(false);
        NumGenText1.setText(resourceMap.getString("NumGenText1.text")); // NOI18N
        NumGenText1.setName("NumGenText1"); // NOI18N
        miann.add(NumGenText1, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 50, 50, -1));

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N
        miann.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 20, -1, -1));

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N
        miann.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 190, -1, -1));

        MisMirAnnText.setText(resourceMap.getString("MisMirAnnText.text")); // NOI18N
        MisMirAnnText.setName("MisMirAnnText"); // NOI18N
        miann.add(MisMirAnnText, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 190, 30, -1));

        jButton7.setBackground(resourceMap.getColor("jButton7.background")); // NOI18N
        jButton7.setText(resourceMap.getString("jButton7.text")); // NOI18N
        jButton7.setBorderPainted(false);
        jButton7.setFocusable(false);
        jButton7.setName("jButton7"); // NOI18N
        jButton7.setOpaque(true);
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        miann.add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 190, 20, 20));

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N
        miann.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 230, -1, -1));

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N
        miann.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 270, -1, -1));

        AddMirAnnText.setText(resourceMap.getString("AddMirAnnText.text")); // NOI18N
        AddMirAnnText.setName("AddMirAnnText"); // NOI18N
        miann.add(AddMirAnnText, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 230, 30, -1));

        TriMirAnnText.setText(resourceMap.getString("TriMirAnnText.text")); // NOI18N
        TriMirAnnText.setName("TriMirAnnText"); // NOI18N
        TriMirAnnText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TriMirAnnTextActionPerformed(evt);
            }
        });
        miann.add(TriMirAnnText, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 270, 30, -1));

        jButton8.setBackground(resourceMap.getColor("jButton8.background")); // NOI18N
        jButton8.setText(resourceMap.getString("jButton8.text")); // NOI18N
        jButton8.setBorderPainted(false);
        jButton8.setFocusable(false);
        jButton8.setName("jButton8"); // NOI18N
        jButton8.setOpaque(true);
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        miann.add(jButton8, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 230, 20, 20));

        jButton9.setBackground(resourceMap.getColor("jButton9.background")); // NOI18N
        jButton9.setText(resourceMap.getString("jButton9.text")); // NOI18N
        jButton9.setBorderPainted(false);
        jButton9.setFocusable(false);
        jButton9.setName("jButton9"); // NOI18N
        jButton9.setOpaque(true);
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });
        miann.add(jButton9, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 270, 20, 20));

        jTabbedPane1.addTab(resourceMap.getString("miann.TabConstraints.tabTitle"), miann); // NOI18N

        cusann.setName("cusann"); // NOI18N
        cusann.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        LoaGenBut.setText(resourceMap.getString("LoaGenBut.text")); // NOI18N
        LoaGenBut.setName("LoaGenBut"); // NOI18N
        LoaGenBut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LoaGenButActionPerformed(evt);
            }
        });
        cusann.add(LoaGenBut, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 110, 160, -1));

        freqtext.setText(resourceMap.getString("freqtext.text")); // NOI18N
        freqtext.setName("freqtext"); // NOI18N
        cusann.add(freqtext, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 80, -1, -1));

        SpeList.setName("SpeList"); // NOI18N
        SpeList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                SpeListMouseReleased(evt);
            }
        });
        SpeList.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                SpeListItemStateChanged(evt);
            }
        });
        cusann.add(SpeList, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 120, 140, 30));

        GenList.setName("GenList"); // NOI18N
        cusann.add(GenList, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 170, 140, 30));

        addtext.setText(resourceMap.getString("addtext.text")); // NOI18N
        addtext.setName("addtext"); // NOI18N
        cusann.add(addtext, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 215, 30, -1));

        mistext.setText(resourceMap.getString("mistext.text")); // NOI18N
        mistext.setName("mistext"); // NOI18N
        cusann.add(mistext, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 215, 30, -1));

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tralist.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        tralist.setName("tralist"); // NOI18N
        jScrollPane1.setViewportView(tralist);

        cusann.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 270, 180, 110));

        LoaTraBut.setText(resourceMap.getString("LoaTraBut.text")); // NOI18N
        LoaTraBut.setName("LoaTraBut"); // NOI18N
        LoaTraBut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LoaTraButActionPerformed(evt);
            }
        });
        cusann.add(LoaTraBut, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 270, 160, -1));

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N
        cusann.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 180, -1, -1));

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N
        cusann.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 10, -1, -1));

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N
        cusann.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 220, -1, -1));

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N
        cusann.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 220, -1, -1));

        lablefreq.setText(resourceMap.getString("lablefreq.text")); // NOI18N
        lablefreq.setName("lablefreq"); // NOI18N
        cusann.add(lablefreq, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 85, -1, -1));

        jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jSeparator2.setName("jSeparator2"); // NOI18N
        cusann.add(jSeparator2, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 0, 20, 400));

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N
        cusann.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 250, -1, -1));

        NumGenText.setBackground(resourceMap.getColor("NumGenText.background")); // NOI18N
        NumGenText.setEditable(false);
        NumGenText.setText(resourceMap.getString("NumGenText.text")); // NOI18N
        NumGenText.setName("NumGenText"); // NOI18N
        cusann.add(NumGenText, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, 50, -1));

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N
        cusann.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 50, -1, -1));

        jButton5.setBackground(resourceMap.getColor("jButton5.background")); // NOI18N
        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setBorderPainted(false);
        jButton5.setFocusable(false);
        jButton5.setName("jButton5"); // NOI18N
        jButton5.setOpaque(true);
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        cusann.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 50, 20, 20));

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N
        cusann.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 210, -1, -1));

        NumTraText.setBackground(resourceMap.getColor("NumTraText.background")); // NOI18N
        NumTraText.setEditable(false);
        NumTraText.setText(resourceMap.getString("NumTraText.text")); // NOI18N
        NumTraText.setName("NumTraText"); // NOI18N
        cusann.add(NumTraText, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 230, 50, -1));

        jButton6.setBackground(resourceMap.getColor("jButton6.background")); // NOI18N
        jButton6.setText(resourceMap.getString("jButton6.text")); // NOI18N
        jButton6.setBorderPainted(false);
        jButton6.setFocusable(false);
        jButton6.setName("jButton6"); // NOI18N
        jButton6.setOpaque(true);
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        cusann.add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 210, 20, 20));

        nameana.setText(resourceMap.getString("nameana.text")); // NOI18N
        nameana.setName("nameana"); // NOI18N
        cusann.add(nameana, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 40, 140, -1));

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N
        cusann.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 130, -1, -1));

        jTabbedPane1.addTab(resourceMap.getString("cusann.TabConstraints.tabTitle"), cusann); // NOI18N

        getContentPane().add(jTabbedPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 60, 550, 460));

        ExpList.setName("ExpList"); // NOI18N
        getContentPane().add(ExpList, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 20, 140, 30));

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 20, -1, -1));

        dobut.setText(resourceMap.getString("dobut.text")); // NOI18N
        dobut.setName("dobut"); // NOI18N
        dobut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dobutActionPerformed(evt);
            }
        });
        getContentPane().add(dobut, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 20, 210, -1));

        CloseCusBut.setText(resourceMap.getString("CloseCusBut.text")); // NOI18N
        CloseCusBut.setName("CloseCusBut"); // NOI18N
        CloseCusBut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CloseCusButActionPerformed(evt);
            }
        });
        getContentPane().add(CloseCusBut, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 530, 210, -1));

        probar.setName("probar"); // NOI18N
        getContentPane().add(probar, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 530, 320, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void CloseCusButActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CloseCusButActionPerformed
        // TODO add your handling code here:
        Runtime.getRuntime().gc();
        dispose();
    }//GEN-LAST:event_CloseCusButActionPerformed

    private void SpeListMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SpeListMouseReleased
        // TODO add your handling code here:
}//GEN-LAST:event_SpeListMouseReleased

    private void SpeListItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_SpeListItemStateChanged
        // TODO add your handling code here:
        
        String host=SeqBusterView.HosMysText.getText();
        String user=SeqBusterView.UseMysText.getText();
        String pssw=SeqBusterView.PswMysText.getText();
        String namepro=SeqBusterView.loaprotext.getText();
        String port=SeqBusterView.PorMysText.getText();
        if (!port.matches("")){host=host+":"+port;}
        
        String spe = (String)SpeList.getSelectedItem();
        Connection con = null;
        try {
            con = (Connection) DriverManager.getConnection("jdbc:mysql://"+host+"/"+namepro,user,pssw);
            Statement statment = (Statement) con.createStatement();
            //statment.executeUpdate("drop table if exists `"+expname+"clusraw` ");
            String readsamples="select `name` from `seqbuster`.`genome` where `specie` like '"+spe+"' ";
            ResultSet rs=statment.executeQuery(readsamples);


            while (rs.next()) {

                GenList.addItem(rs.getString(1));

            }
        } catch (SQLException ex) {
            Logger.getLogger(NonMiRNAFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_SpeListItemStateChanged

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(null,"Show the number of genomes loaded to SeqBuster.");
}//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(null,"Show the number of tracks features (ncRNA,repeat...) loaded to SeqBuster.");
}//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(null,"Number of mismatch allowed in the alignment.");
}//GEN-LAST:event_jButton7ActionPerformed

    private void TriMirAnnTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TriMirAnnTextActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_TriMirAnnTextActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(null,"Number of nucleotides allowed as additions respect with the reference miRNA.");
}//GEN-LAST:event_jButton8ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(null,"Number of nucleotides allowed as variations at the ends of the reference miRNA.");
}//GEN-LAST:event_jButton9ActionPerformed

    private void LoaGenButActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LoaGenButActionPerformed
        // TODO add your handling code here:
        JDialog loadgenome_obj = new LoaNewGenFrame(this);
        loadgenome_obj.setLocationRelativeTo(this);
        loadgenome_obj.setVisible(true);
        dobut.setEnabled(true);
    }//GEN-LAST:event_LoaGenButActionPerformed

    private void LoaTraButActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LoaTraButActionPerformed
        // TODO add your handling code here:
        JDialog loadgenome_obj = new LoaNewTraFrame(this);
        loadgenome_obj.setLocationRelativeTo(this);
        loadgenome_obj.setVisible(true);
    }//GEN-LAST:event_LoaTraButActionPerformed

    private void dobutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dobutActionPerformed
        // TODO add your handling code here:
        if (cusann.isShowing()){

            cusannmethod();
        }else{
            miannmethod();

        }
    }//GEN-LAST:event_dobutActionPerformed
    private void miannmethod(){
        

    }
    private void cusannmethod (){
        Date date = new Date();
        HelpDesk.reload();
        HelpDesk.helptext.setText("Processed started at: "+date+"\n");
        HelpDesk.bar.setValue(0);
        HelpDesk.bar.setStringPainted(true);
        //infoFrame.infText.setText("Doing clustering");
        info_obj = new infoFrame("Doing mapping");
        info_obj.setLocationRelativeTo(this);
        info_obj.dispose();

        Runnable view = new Runnable() {

        public void run() {

        String megablast=SeqBusterView.pathblast.getText()+"/blastn";
        //do fasta file
        String expname = (String)ExpList.getSelectedItem();
        String db = (String)GenList.getSelectedItem();
        String spe = (String)SpeList.getSelectedItem();
        String pathout=SeqBusterView.pathout.getText()+"/";
        String host=SeqBusterView.HosMysText.getText();
        String user=SeqBusterView.UseMysText.getText();
        String pssw=SeqBusterView.PswMysText.getText();
        String namepro=SeqBusterView.loaprotext.getText();
        String port=SeqBusterView.PorMysText.getText();



        if (!port.matches("")){host=host+":"+port;}

        int nf=0;
        String nameana=CusAnnFrame.nameana.getText();
        probar.setValue(10);
        probar.repaint();

        Connection con = null;
        CusAnn clu= new CusAnn();
        int countseq=0;

        HelpDesk.helptext.append("selecting sequences with count>= "+freqtext.getText()+"\n");


        try {
            con = (Connection) DriverManager.getConnection ("jdbc:mysql://"+host+"/"+namepro,user,pssw);
            Statement statment = (Statement) con.createStatement();
            ResultSet rs=statment.executeQuery("select `name` from `experiments` where `name` like '"+expname+nameana+"' limit 0,1");


            Boolean doit=true;
            if (rs.next()){
                Object[] options = {"Yes","No"};

                int n = JOptionPane.showOptionDialog(null,"This table exists, would you like to repeat the analysis?","Warning",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,options,options[0]);
                if (n==1){
                   doit=false;
                }else{
                    statment.executeUpdate("drop table `"+expname+"clusraw`");
                    statment.executeUpdate("delete from `experiments` where `name` like  '"+expname+nameana+"'");
                }
            }
           if (doit==true){

               statment.executeUpdate("insert into `experiments` values ('" + expname + nameana + "','" + namepro + "','show','user')");
               String readsamples = "select `seq`,`freq`,`id` from `" + expname + "` where (`DB` not like 'miRNA' or `DB` not like 'misRNA') and `freq`>=" + freqtext.getText();
               rs = statment.executeQuery(readsamples);
               try {
                   PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(pathout + namepro + "/" + expname + "/seqstemp.fa")));


                   while (rs.next()) {
                       countseq++;
                       out.write(">seq_" + rs.getInt(3) + "_" + rs.getInt(2) + "\n" + rs.getString(1) + "\n");
                   }
                   out.close();
               } catch (IOException ex) {
                   Logger.getLogger(NonMiRNAFrame.class.getName()).log(Level.SEVERE, null, ex);
                   JOptionPane.showMessageDialog(null, "Error: copy this error and send to lorena.pantano@crg.es: " + ex);
               }

                    HelpDesk.helptext.append("Number of sequences selected: " + countseq + "\n");

                    infoFrame.infText.setCaretPosition(0);
                    infoFrame.infText.append("mapping\n");

                    Runtime runtime = Runtime.getRuntime();
                    Process process = null;

                    HelpDesk.helptext.append("Mapping sequences against: " + db + "\nnumber of files to map: " + nf+" (300 sequences/20 minutes/2 cores in human)\n");


                            //System.out.println(children[i]);
                            String cmdmegablast = megablast + " -task megablast -db DB/" + db + "_" + spe + ".db -query " + pathout + namepro + "/" + expname + "/seqstemp.fa"+ " -word_size 7 -num_threads 2 -evalue 1 -perc_identity 85 " + " -outfmt 6" + " -out " + pathout + namepro + "/" + expname + "/seqstemp"  + ".megablast";
                            try {
                                //DoRuntime(cmdmegablast);

                                process = runtime.exec(cmdmegablast);
                                try {
                                    process.waitFor();
                                } catch (InterruptedException ex) {
                                    Logger.getLogger(NonMiRNAFrame.class.getName()).log(Level.SEVERE, null, ex);
                                    JOptionPane.showMessageDialog(null, "Error: copy this error and send to lorena.pantano@crg.es: " + ex);
                                }
                            } catch (IOException ex) {
                                Logger.getLogger(NonMiRNAFrame.class.getName()).log(Level.SEVERE, null, ex);
                                JOptionPane.showMessageDialog(null, "Error: copy this error and send to lorena.pantano@crg.es: " + ex);
                            }

                HelpDesk.bar.setValue(25);

                probar.setValue(25);
                probar.repaint();
                try {
                    clu.parse(expname, nameana, db, spe);
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(CusAnnFrame.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(null, "Error: copy this error and send to lorena.pantano@crg.es: " + ex);
                } catch (IOException ex) {
                    Logger.getLogger(CusAnnFrame.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(null, "Error: copy this error and send to lorena.pantano@crg.es: " + ex);
                }

               HelpDesk.bar.setValue(50);
               //parse and add result to table
               HelpDesk.helptext.append("Annotating started: " + new Date() + "\n");
               int[] selectedIx = tralist.getSelectedIndices();
               for (int i = 0; i < selectedIx.length; i++) {

                   Object sel = tralist.getModel().getElementAt(selectedIx[i]);
                   infoFrame.infText.setCaretPosition(0);
                   infoFrame.infText.setText("annotate aginst: " + sel + "\n");
                   infoFrame.infText.setForeground(Color.RED);
                   infoFrame.infText.append("WAIT...\n");
                   infoFrame.infText.setForeground(Color.BLACK);


                   try {

                       clu.mapping(expname ,nameana, namepro, sel.toString(), spe);

                   } catch (IOException ex) {
                       Logger.getLogger(NonMiRNAFrame.class.getName()).log(Level.SEVERE, null, ex);
                       JOptionPane.showMessageDialog(null, "Error: copy this error and send to lorena.pantano@crg.es: " + ex);
                   }



               }

                probar.setValue(75);
                probar.repaint();

               HelpDesk.bar.setValue(75);


               String msg = "Now you can go to usRNA analysis to get the characterization\n";
               msg = msg + " or go to Manage data to browse yourself usRNAs by selecting the last option in that panel\n";
               msg = msg + "You can add a new annotation coming here later, select only the last step in the right panel\n and the new database you want to add to the annotation.";

               JOptionPane.showMessageDialog(null,msg);


               info_obj.dispose();
               HelpDesk.bar.setValue(100);
               probar.setValue(100);
               probar.repaint();
               HelpDesk.helptext.append("Process finished at: "+new Date()+"\n");
        }

            rs.close();
            statment.close();
            con.close();
        } catch (SQLException ex) {
            Logger.getLogger(NonMiRNAFrame.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null,"Error: copy this error and send to lorena.pantano@crg.es: "+ex);
        }

        Runtime.getRuntime().gc();
            }
        };
        Thread nThread2 = new Thread(view);
        nThread2.start();

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JTextField AddMirAnnText;
    private javax.swing.JButton CloseCusBut;
    public static javax.swing.JComboBox DBList;
    public static javax.swing.JComboBox ExpList;
    public static javax.swing.JComboBox GenList;
    private javax.swing.JButton LoaGenBut;
    private javax.swing.JButton LoaTraBut;
    public static javax.swing.JTextField MisMirAnnText;
    public static javax.swing.JTextField NumGenText;
    public static javax.swing.JTextField NumGenText1;
    public static javax.swing.JTextField NumTraText;
    public static javax.swing.JComboBox SpeList;
    public static javax.swing.JTextField TriMirAnnText;
    public static javax.swing.JTextField addtext;
    private javax.swing.JPanel cusann;
    private javax.swing.JButton dobut;
    private javax.swing.JTextField freqtext;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lablefreq;
    private javax.swing.JPanel miann;
    public static javax.swing.JTextField mistext;
    public static javax.swing.JTextField nameana;
    private javax.swing.JProgressBar probar;
    public static javax.swing.JList tralist;
    // End of variables declaration//GEN-END:variables
    public JDialog info_obj;

}
